<template>
  <el-select-v2
    v-model="model[item.prop]"
    size="default"
    v-bind="item"
    :placeholder="item.placeholder || '请选择' + item.label"
    :clearable="item.clearable === false ? false : true"
    :options="fmtOption"
    v-on="item.events || {}"
    :style="item.v2Style || { width: '100%' }"
  >
  </el-select-v2>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
  item: Object,
  model: Object
})
// 处理自定义数据的key value字段名称与默认不一致的问题
const fmtOption = computed(() => {
  const fmt = props.item.options.map((option) => {
    return {
      ...option,
      label: option['label'] || option[props.item.labelName],
      value: option['value'] || option[props.item.valueName],
      disabled: option['disabled'] || option[props.item.disabledKey]
    }
  })
  return fmt
})
</script>
